#include "sort.h"
#include "stack.h"


void test_op()
{
	srand((unsigned int)time(0));
	const int N = 100000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	if (a1 == NULL)
	{
		exit(1);
	}

	int* a2 = (int*)malloc(sizeof(int) * N);
	if (a2 == NULL)
	{
		exit(1);
	}

	int* a3 = (int*)malloc(sizeof(int) * N);
	if (a3 == NULL)
	{
		exit(1);
	}
	int* a4 = (int*)malloc(sizeof(int) * N);
	if (a4 == NULL)
	{
		exit(1);
	}
	int* a5 = (int*)malloc(sizeof(int) * N);
	if (a5 == NULL)
	{
		exit(1);
	}
	int* a6 = (int*)malloc(sizeof(int) * N);
	if (a6 == NULL)
	{
		exit(1);
	}
	int* a7 = (int*)malloc(sizeof(int) * N);
	if (a7 == NULL)
	{
		exit(1);
	}
	int* a8 = (int*)malloc(sizeof(int) * N);
	if (a8 == NULL)
	{
		exit(1);
	}
	int* a9 = (int*)malloc(sizeof(int) * N);
	if (a9 == NULL)
	{
		exit(1);
	}
	for (int i = 0; i < N; ++i)
	{
		a1[i] = rand();
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
		a8[i] = a1[i];
		a9[i] = a1[i];
	}

	

	int begin1 = clock();
	insert_sort(a1, N);
	int end1 = clock();

	int begin2 = clock();
	shell_sort(a2, N);
	int end2 = clock();

	int begin3 = clock();
	select_sort(a3, N);
	int end3 = clock();

	int begin4 = clock();
	heap_sort_down(a4, N);
	int end4 = clock();

	int begin5 = clock();
	heap_sort_up(a5, N);
	int end5 = clock();

	int begin6 = clock();
	quick_sort(a6, 0, N - 1);
	int end6 = clock();

	int begin7 = clock();
	merge_sort(a7, N);
	int end7 = clock();

	int begin8 = clock();
	bubble_sort(a8, N);
	int end8 = clock();

	int begin9 = clock();
	count_sort(a9, N);
	int end9 = clock();

	printf("InsertSort:%d\n", end1 - begin1);
	printf("ShellSort:%d\n", end2 - begin2);
	printf("SelectSort:%d\n", end3 - begin3);
	printf("HeapSort_down:%d\n", end4 - begin4);
	printf("HeapSort_up:%d\n", end5 - begin5);
	printf("QuickSort:%d\n", end6 - begin6);
	printf("MergeSort:%d\n", end7 - begin7);
	printf("bubble_sort:%d\n", end8 - begin8);
	printf("count_sort:%d\n", end9 - begin9);

	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
	free(a8);
}

void test_insert_sort()
{
	int a[] = { 1, 3, 7, 2, 9, 5, 10, 5 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	insert_sort(a, size);
	print_array(a, size);
}

void test_shell_sort()
{
	int a[] = { 1, 3, 7, 2, 9, 5, 10, 5 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	shell_sort(a, size);
	print_array(a, size);
}

void test_select_sort()
{
	int a[] = { 1, 3, 7, 2, 9, 5, 10, 5 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	select_sort(a, size);
	print_array(a, size);
}

void test_heap_sort_down()
{
	int a[] = { 1, 3, 7, 2, 9, 5, 10, 5 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	heap_sort_down(a, size);
	print_array(a, size);
}

void test_heap_sort_up()
{
	int a[] = { 1, 3, 7, 2, 9, 5, 10, 5 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	heap_sort_up(a, size);
	print_array(a, size);
}

void test_bubble_sort()
{
	int a[] = { 1, 3, 7, 2, 9, 5, 10, 5 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	bubble_sort(a, size);
	print_array(a, size);
}


void test_quick_sort()
{
	int a[] = { 8, 1, 2, 7, 9, 3, 4, 5, 10, 6 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	quick_sort(a, 0, size - 1);
	print_array(a, size);
}

void test_quick_sort_non_r()
{
	int a[] = { 8, 1, 2, 7, 9, 3, 4, 5, 10, 6 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	quick_sort_non_r(a, 0, size - 1);
	print_array(a, size);
}

void test_merge_sort()
{
	int a[] = { 8, 1, 2, 7, 9, 3, 4, 5, 10, 6 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	merge_sort(a, size);
	print_array(a, size);
}

void test_merge_sort_non_r()
{
	int a[] = { 8, 1, 2, 7, 9, 3, 4, 5, 6};
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	merge_sort_non_r(a, size);
	print_array(a, size);
}

void test_count_sort()
{
	int a[] = { 8, 1, 2, 7, 9, 3, 4, 5, 6 };
	int size = sizeof(a) / sizeof(a[0]);
	print_array(a, size);
	count_sort(a, size);
	print_array(a, size);
}


int main()
{
	//test_op();
	//test_insert_sort();
	//test_shell_sort();
	//test_select_sort();
	//test_heap_sort_down();
	//test_heap_sort_up();
	//test_bubble_sort();
	//test_quick_sort();
	//test_quick_sort_non_r();
	//test_merge_sort();
	//test_merge_sort_non_r();
	test_count_sort();
	return 0;
}